/**********************************************************
 * UserRegistrationStatisticsAction.java
 * Created by ankur
 * Last modified Date: Aug 5, 2008 11:37:55 AM by ankur
 * Version : 0.1
 * Copyright (c) 2008 - 2008 cyberThink Infotech Pvt. Ltd., All rights reserved.
 **********************************************************/
package com.printeverywhere.action;

import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;

import com.opensymphony.xwork2.ActionSupport;
import com.printeverywhere.delegator.UserServiceDelegator;
import com.printeverywhere.dto.UserDateCount;
import com.printeverywhere.util.DateUtil;
import static com.printeverywhere.util.LoggerConstants.*;

/**
 * The Class UserRegistrationStatisticsAction.
 */
public class UserRegistrationStatisticsAction extends ActionSupport {
	
	/** The log. */
	private static Logger log = Logger.getLogger(UserRegistrationStatisticsAction.class);
	
	/**
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	public String execute() throws Exception{
		if(days>0){
			if(log.isInfoEnabled()){
			log.info(USERS_LIST_BEFORE + days +DAYS);
			}
			list = UserServiceDelegator.getRegisteredUserListAfterThisDate(DateUtil.getPriviousDateFromCurrent(days));
		}
		else{
			if(log.isInfoEnabled())
			log.info(USERS_LIST);
			list = UserServiceDelegator.getRegisteredUserListAfterThisDate(DateUtil.getFirstDate());
		}
		totalUserRegistered=0;
		for (Iterator<UserDateCount> iterator = list.iterator(); iterator.hasNext();) {
			UserDateCount name = iterator.next();
			totalUserRegistered = totalUserRegistered + name.getCount();	
		}
		
		return SUCCESS;
	}
	
	/** The days. */
	private int days;
	
	/** The total user registered. */
	private int totalUserRegistered;
	
	/** The list. */
	private List<UserDateCount> list;
	
	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;

	/**
	 * Gets the days.
	 * 
	 * @return the days
	 */
	public int getDays() {
		return days;
	}

	/**
	 * Sets the days.
	 * 
	 * @param days the new days
	 */
	public void setDays(int days) {
		this.days = days;
	}

	/**
	 * Gets the total user registered.
	 * 
	 * @return the total user registered
	 */
	public int getTotalUserRegistered() {
		return totalUserRegistered;
	}

	/**
	 * Sets the total user registered.
	 * 
	 * @param totalUserRegistered the new total user registered
	 */
	public void setTotalUserRegistered(int totalUserRegistered) {
		this.totalUserRegistered = totalUserRegistered;
	}

	/**
	 * Gets the list.
	 * 
	 * @return the list
	 */
	public List<UserDateCount> getList() {
		return list;
	}

	/**
	 * Sets the list.
	 * 
	 * @param list the new list
	 */
	public void setList(List<UserDateCount> list) {
		this.list = list;
	}

	}